<template>
	<view class="box">
		<publicList :list="list" :options="options" @detail="detail" @savestate="savestate" @bindClick="bindClick" @search="search" :addpageUrl="'/pages/quickly/medicalReport/entryPage'" ></publicList>
	</view>
</template>

<script>
	import publicList from '@/components/publicList/index.vue'
	export default {
		components:{publicList},
		data () {
			return {
				pageIndex:1,
				pageSize: 20,	
				list: [],
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#EE2437' // 删除按钮背景  红的
					}
				}],
				SearchuserId:'',
				page: 1,
				nullData: false,
				deleteList:''
			}
		},
		onLoad(){
			this.getlist({pageIndex:this.pageIndex,pageSize:this.pageSize,userId:this.SearchuserId})
		},
		methods:{
			search(e) {
				this.page = 1
				this.nullData = false
				this.$api.MedicalList({pageSize:10,pageIndex:1,userName:e}).then(res=>{
					var data =  res.data.result && res.data.result.elements
					this.list = data
					if(this.list.length >= res.data.result.totalCount){
						this.nullData = true;
					}
				})
			},
			getlist(data){
				this.$api.MedicalList(data).then((res)=>{
					var data = res.data.result.elements;
					if(this.deleteList == 1) {
						this.list = []
						this.list = data
						this.deleteList = ''
					}else {
						this.list = this.list ? this.list.concat(data) : data
						if(this.list.length >= res.data.result.totalCount){
							this.nullData = true;
						}
					}
				})
			},
			detail(item) {
				if(item.type == 1){
					if(item.status == 2){
						uni.navigateTo({
							url: '/pages/quickly/medicalReport/photoUpload?id='+item.id+'&status='+item.status
						})
					}else if(item.status == 4){
						uni.navigateTo({
							url: '/pages/quickly/medicalReport/photoUpload?id='+item.id+'&status='+item.status
						})
					}
				}else{
					window.location.href = 'http://health.jlm12580.com/web/viewer.html?file='+item.imgUrls[0]
				}
			},
			savestate(item) {
				item.status = 2;
				this.$api.Medicalupdate(item).then((res) => {
					if(res.data.returnCode == 200) {
						this.page = 1
						this.deleteList = 1;
						this.nullData = false;
						this.getlist({pageIndex:this.pageIndex,pageSize:this.pageSize,userId:this.SearchuserId})
					}
				})
			},
			bindClick(item) {
				this.$api.HealthExaminationReportDelete(item.id).then((res) => {
					if(res.data.returnCode == 200) {
						this.page = 1
						this.deleteList = 1;
						this.nullData = false;
						this.getlist({pageIndex:this.pageIndex,pageSize:this.pageSize,userId:this.SearchuserId})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
